import request from '@/utils/request';
import {baseurl} from './baseurl'
export interface setDocumentParams {
  content: string;
  url: string;
  type:string;
}
export async function setDocument(params: setDocumentParams) {
  /* 管理员写文档 */
  const data = new FormData();
  if(params.type){
  data.append('type', params.type);
  }
  data.append('content', params.content);
  return request(`${baseurl}index/index/${params.url}`, {
    method: 'POST',
    data,
  });
}

export async function getDocument(url:string,type:any) {
  /* 获取文档 */
  const data = new FormData();
  if(type){
    data.append('type', type);
    }
  return request(`${baseurl}index/index/${url}`, {
    method: 'POST',
    data,
  });
}


export interface settingParams {
  exercise_num: any;
  exercise_integral: any;
  simulation_integral: any;
  default_integral: any;
  permissions_day:any;
  exam_send:any;
  learn_alert:any;
}
export async function setting(params: settingParams) {
  /* 设置 */
  const data = new FormData();
  data.append('exercise_num', params.exercise_num);
  data.append('exercise_integral', params.exercise_integral);
  data.append('simulation_integral', params.simulation_integral);
  data.append('default_integral', params.default_integral);
  data.append('permissions_day', params.permissions_day);
  if( params.exam_send){
    data.append('exam_send', params.exam_send);
  }
  if( params.learn_alert){
    data.append('learn_alert', params.learn_alert);
  }
  return request(`${baseurl}index/index/setting`, {
    method: 'POST',
    data,
  });
}

export async function settingShow() {
  /* 获取设置 */
  return request(`${baseurl}index/index/setting_show`, {
    method: 'POST',
  });
}

export async function simulationPoints(uid) {
  /* 考试前调用该接口扣分 */
  const data = new FormData();
  data.append('uid', uid);
  const is_sw = JSON.parse((localStorage.getItem('userinfo')||'')).is_sw;
  if(is_sw){
    data.append('is_sw',is_sw);
  }
  return request(`${baseurl}index/index/simulation_points`, {
    method: 'POST',
    data
  });
}
export async function exercisePoints(uid) {
  /* 练习前调用该接口扣分 */
  const data = new FormData();
  data.append('uid', uid);
  const is_sw = JSON.parse((localStorage.getItem('userinfo')||'')).is_sw;
  if(is_sw){
    data.append('is_sw',is_sw);
  }
  return request(`${baseurl}index/index/exercise_points`, {
    method: 'POST',
    data
  });
}

export interface applyFormParams {
  page: any;
  name:string;
  id_number:string;
  start_date:string;
  end_date:string;
}
export async function applyForm(params:applyFormParams) {
  /* 申请表管理 */
  const data = new FormData();
  data.append('page', params.page);
  data.append('name', params.name);
  data.append('id_number', params.id_number);
  data.append('start_date', params.start_date);
  data.append('end_date', params.end_date);
  return request(`${baseurl}index/index/px_apply`, {
    method: 'POST',
    data,
  });
}
export async function delApply(params:any) {
  /* 申请表删除 */
  const data = new FormData();
  data.append('id', params.id);
  return request(`${baseurl}index/index/del_apply`, {
    method: 'POST',
    data,
  });
}
export interface editApplyParams {
  name:string;
  id_number:string;
  culture:string,
  work_unit:string,
  province:string,
  city:string,
  district:string,
  work_unit_site:string,
  provinces:string,
  citys:string,
  districts:string,
  work_unit_sites:string,
  cprovince:string,
  ccity:string,
  cdistrict:string,
  cwork_unit_site:string,
  postcode:string,
  phone:string,
  level2:string,
  level3:string,
  level2_text:string,
  level3_text:string,
  job_resume:string, 
  resume:string, 
  unit_contact:string;
  unit_phone:string;
  certificate_number:string;
  id:string;
  opening_date:string;
  test_nature:string;
  test_item:string;
  certificate:string;
  test_items:string;
  test_time:string;

}
export async function editApply(params:editApplyParams) {
  /* 申请表管理 */
  const data = new FormData();
  data.append('name', params.name);
  data.append('id_number', params.id_number);
  data.append('name',params.name);
  data.append('id_number',params.id_number);
  data.append('culture',params.culture),
  data.append('work_unit',params.work_unit),
  data.append('province',params.province),
  data.append('city',params.city),
  data.append('district',params.district),
  data.append('work_unit_site',params.work_unit_site),
  data.append('cprovince',params.cprovince),
  data.append('ccity',params.ccity),
  data.append('cdistrict',params.cdistrict),
  data.append('cwork_unit_site',params.cwork_unit_site),
  data.append('provinces',params.provinces),
  data.append('citys',params.citys),
  data.append('districts',params.districts),
  data.append('work_unit_sites',params.work_unit_sites),
  data.append('postcode',params.postcode),
  data.append('phone',params.phone),
  data.append('level2',params.level2),
  data.append('level3',params.level3),
  data.append('level2_text',params.level2_text),
  data.append('level3_text',params.level3_text),
  data.append('job_resume',params.job_resume), 
  data.append('unit_contact',params.unit_contact);
  data.append('unit_phone',params.unit_phone);
  data.append('certificate_number',params.certificate_number);
  data.append('resume',params.resume);
  data.append('opening_date',params.opening_date);
  data.append('test_nature',params.test_nature);
  data.append('test_item',params.test_item);
  data.append('certificate',params.certificate);
  data.append('test_time',params.test_time);
  data.append('test_items',params.test_items);

  data.append('id',params.id);
  return request(`${baseurl}index/index/up_apply`, {
    method: 'POST',
    data,
  });
}

export async function getProvince() {
  /* 省 */
  return request(`${baseurl}index/index/province`, {
    method: 'POST',
  });
}

export async function getCity(params) {
  /* 市 */
  const data = new FormData();
data.append('id',params.id);
  return request(`${baseurl}index/index/city`, {
    method: 'POST',
    data
  });
}
export async function getDistrict(params) {
  /* 区 */
  const data = new FormData();
data.append('id',params.id);
  return request(`${baseurl}index/index/city`, {
    method: 'POST',
    data
  });
}


export async function setBanner(list) {
  /* 轮播图设置 */
  const data = new FormData();
  for (let i = 0; i < list.length; i++) {
    const item = list[i];
      if(item.file&&item.file[0]&&item.file[0].originFileObj){
        data.append('doc'+i,item.file[0].originFileObj)
      }
      data.append('content'+i,item.content)
      data.append('sort'+i,item.sort)
  }
  return request(`${baseurl}index/index/banner`, {
    method: 'POST',
    data,
  });
}
export async function getBanner() {
  /* 获取轮播图 */
 
  return request(`${baseurl}index/index/get_banner`, {
    method: 'POST',
  });
}